package main

import "fmt"

type Celsius float64    // 摄氏温度
type Fahrenheit float64 // 华氏温度
const (
	AbsoluteZeroC Celsius = -273.15 // 绝对零度
	FreezingC     Celsius = 0       // 结冰点温度
	BoilingC      Celsius = 100     // 沸水温度
)

func CToF(c Celsius) Fahrenheit  { return Fahrenheit(c*9/5 + 32) }
func FToC(f Fahrenheit) Celsius  { return Celsius((f - 32) * 5 / 9) }
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }

func main() {
	fmt.Printf("%g\n", BoilingC-FreezingC) // "100"
	boilingF := CToF(BoilingC)
	fmt.Printf("%g\n", boilingF-CToF(FreezingC)) // "180"
	//fmt.Printf("%g\n", boilingF-FreezingC)      --compile error: type mismatch
	var c Celsius
	var f Fahrenheit
	fmt.Println(c == 0) // "true"
	fmt.Println(f >= 0) // "true"
	//fmt.Println(c == f)    //"=="比较运算符需要比较两个类型相等的,不然报错
	fmt.Println(c == Celsius(f)) // "true"!

	c = FToC(212.0)
	j := FToC(203.0)
	fmt.Println("j =", j.String())
	fmt.Println("下面是c:")
	fmt.Println(c.String()) // "100°C"
	fmt.Printf("%v\n", c)   // "100°C"; no need to call String explicitly
	fmt.Printf("%s\n", c)   // "100°C"
	fmt.Println(c)          // "100°C"
	fmt.Printf("%g\n", c)   // "100"; does not call String
	fmt.Println(float64(c)) // "100"; does not call String
	fmt.Printf("%f\n", c)   // "100.000000"; does not call String

	d, h := 12345.455646468794, 0.0000568
	fmt.Printf("%e\t%e", d, h)
}
